package com.survey.demo.ui.activity;

import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;
import com.hjq.widget.layout.WrapRecyclerView;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;
import com.survey.demo.R;
import com.survey.demo.app.AppActivity;
import com.survey.demo.http.bean.StaffEntity;
import com.survey.demo.http.glide.GlideApp;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

/**
 * 企业员工管理
 */
public class StaffManageActivity extends AppActivity implements OnRefreshLoadMoreListener {
    private SmartRefreshLayout mRefreshLayout;
    private WrapRecyclerView mRecyclerView;
    private List<StaffEntity> list = new ArrayList<>();
    private  BaseQuickAdapter adapter;
    private TitleBar titleBar;
    @Override
    protected int getLayoutId() {
        return R.layout.staffmanage_activity;
    }

    @Override
    protected void initView() {
        mRefreshLayout = findViewById(R.id.rl_status_refresh);
        mRecyclerView = findViewById(R.id.car_recycle);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter =new BaseQuickAdapter<StaffEntity, BaseViewHolder>(R.layout.staff_item, list) {
            @Override
            protected void convert(@NotNull BaseViewHolder baseViewHolder, StaffEntity bean) {
                ImageView img =  (ImageView)baseViewHolder.getView(R.id.img_dianpu);
                TextView name =  (TextView)baseViewHolder.getView(R.id.name_tv);
                TextView job =  (TextView)baseViewHolder.getView(R.id.job_tv);
                name.setText(bean.getName());
                job.setText(bean.getJob());
                GlideApp.with(StaffManageActivity.this)
                        .load(R.drawable.example_bg)
                        .transform(new MultiTransformation<>(new CenterCrop(), new CircleCrop()))
                        .into(img);
                baseViewHolder.getView(R.id.edit_tv).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        startActivity(CreateStaffActivity.class);
                    }
                });
            }
        };
        mRecyclerView.setAdapter(adapter);
        mRefreshLayout.setOnRefreshLoadMoreListener(this);
        titleBar = findViewById(R.id.top);
        titleBar.setOnTitleBarListener(new OnTitleBarListener() {
            @Override
            public void onLeftClick(View v) {
                finish();
            }

            @Override
            public void onTitleClick(View v) {

            }

            @Override
            public void onRightClick(View v) {
                startActivity(CreateStaffActivity.class);
            }
        });
    }

    @Override
    protected void initData() {
        for(int i = 0;i<4;i++){
            StaffEntity entity = new StaffEntity();
            entity.setImg("");
            entity.setName("金宝三");
            entity.setJob("蓝图信息。人事专员");
            list.add(entity);
        }
        adapter.setNewData(list);
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {
        postDelayed(() -> {
//            mAdapter.clearData();
//            mAdapter.setData(analogData());
            mRefreshLayout.finishRefresh();
        }, 1000);
    }

    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
        postDelayed(() -> {
            //mAdapter.addData(analogData());
            mRefreshLayout.finishLoadMore();

            //mAdapter.setLastPage(mAdapter.getItemCount() >= 100);
            //mRefreshLayout.setNoMoreData(mAdapter.isLastPage());
        }, 1000);
    }
}
